class Solution {
public:
    int reverse(int x) {
        int result = 0;
        int temp = 0;
        //int d = 1;
        //if(x<0) d=-1;
        while(x!=0)
        {
            if(result >=INT_MAX/10+1 or result <= INT_MIN/10-1) return 0;
            temp = x%10;
            x = x / 10;
            result = result*10+temp;
        }
        return result;
    }
};
